
package com.dps.omc.service.impl;
import com.dps.omc.model.Job;
import com.dps.omc.model.PreScript;
import com.dps.omc.service.IPreScriptService;
import com.dps.omc.service.IJobPreScriptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dps.common.service.impl.AbstractPageService;
import com.dps.omc.dao.IJobPreScriptDAO;
import com.dps.omc.model.JobPreScript;

import java.util.List;

@SuppressWarnings("unchecked")
@Service("JobPreScriptServiceImpl")

public class JobPreScriptServiceImpl extends AbstractPageService<IJobPreScriptDAO,JobPreScript> implements IJobPreScriptService {

	@Autowired
	private IJobPreScriptDAO jobPreScriptDAO;
	@Autowired
	private IPreScriptService preScriptService;
	@Override
	public boolean getEnableDataPerm() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public IJobPreScriptDAO getDao() {
		return jobPreScriptDAO;
	}

	@Override
	public void create(Job job, List<String> preScriptIds) {
		for(String preScriptId:preScriptIds)
		{
			PreScript preScript = preScriptService.fetch(preScriptId);
			if(preScript!=null)
			{
				JobPreScript jobPreScript = new JobPreScript();
				jobPreScript.setJobId(job.getId());
				jobPreScript.setPreScriptId(preScriptId);
				jobPreScript.setArtifactId(preScript.getArtifactId());
				jobPreScript.setArtifactName(preScript.getArtifactName());
				jobPreScript.setStoreName(preScript.getStoreName());
				jobPreScript.setStorePath(preScript.getStorePath());
				this.add(jobPreScript);
			}
		}
	}
}
